package exercises.leetcode;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * <a href="">
 * </a>
 *
 * <p><span color="#87CEEB">描述:</span>
 *
 * @author or2
 * @date 2021年10月24日 时间: 9:16
 */
public class Saike_01_B {
    public static void main(String[] args) {
//        Scanner scanner = new Scanner(System.in);
        Scanner scanner = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        int[][] ranges = new int[10][n + 2];
        ArrayList<Integer> res = new ArrayList<>();
        for (int i = 0; i < q; i++) {
            int operator = scanner.nextInt();
            if (operator == 1) {
                int a = scanner.nextInt();
                int l = scanner.nextInt();
                int r = scanner.nextInt();
                int k = scanner.nextInt();
                for (int j = 0; j < 10; j++) {
                    if ((a & 1) == 1) for (int t = l; t <= r; t++) ranges[j][t] += k;
                    a >>>= 1;
                }
            } else {
                int a = scanner.nextInt();
                int l = scanner.nextInt();
                int r = scanner.nextInt();
                int sum = 0;
                for (int j = 0; j < 10; j++) {
                    if ((a & 1) == 1) for (int t = l; t <= r; t++) sum += ranges[j][t];
                    a >>>= 1;
                }
                res.add(sum);
            }
        }

        for (Integer re : res) System.out.println(re);
    }
}
